from rest_framework import serializers
from users import models
import re


def verify(value):
    phone = re.match(r"^[0-9]{11}$",value)
    if phone:
        return value
    else:
        raise serializers.ValidationError("数据不合规")


class UserSer(serializers.ModelSerializer):
    class Meta:
        model = models.User
        fields = "__all__"
        extra_kwargs = {"phone":{"required":True,"validators":[verify]}}
